package cn.edu.sdjzu.xg.eagle.controller;

import cn.edu.sdjzu.xg.eagle.entities.ClubApplication;
import cn.edu.sdjzu.xg.eagle.service.ClubApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("clubApplications")
public class ClubApplicationController {

    @Autowired
    private ClubApplicationService clubApplicationService;

    // 查询所有社团申请记录
    @GetMapping
    public List<ClubApplication> findAllClubApplications() {
        return clubApplicationService.findAllClubApplications();
    }

    // 根据申请人 ID 和申请时间查询特定的社团申请记录
    @GetMapping("/{applicantId}/{applyTime}")
    public ClubApplication findClubApplicationByIdAndTime(@PathVariable Integer applicantId, @PathVariable java.sql.Timestamp applyTime) {
        return clubApplicationService.findClubApplicationByIdAndTime(applicantId, applyTime);
    }

    // 插入一条新的社团申请记录
    @PostMapping
    public String addClubApplication(@RequestBody ClubApplication clubApplication) {
        int result = clubApplicationService.addClubApplication(clubApplication);
        if (result > 0) {
            return "添加社团申请记录成功";
        } else {
            return "添加社团申请记录失败";
        }
    }

    // 更新社团申请记录
    @PutMapping
    public String updateClubApplication(@RequestBody ClubApplication clubApplication) {
        int result = clubApplicationService.updateClubApplication(clubApplication);
        if (result > 0) {
            return "更新社团申请记录成功";
        } else {
            return "更新社团申请记录失败，未找到对应记录";
        }
    }

    // 根据申请人 ID 和申请时间删除特定的社团申请记录
    @DeleteMapping("/{applicantId}/{applyTime}")
    public String deleteClubApplication(@PathVariable Integer applicantId, @PathVariable java.sql.Timestamp applyTime) {
        int result = clubApplicationService.deleteClubApplication(applicantId, applyTime);
        if (result > 0) {
            return "删除社团申请记录成功";
        } else {
            return "删除社团申请记录失败，未找到对应记录";
        }
    }
}